#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        if(n<2) return n;
        int newn = 0;
        //去除横线
        for(int i=1; i<n; ++i){
            if(nums[i]-nums[i-1]!=0){
                nums[newn++] = nums[i]-nums[i-1];
            }
        }
        if(newn==0) return 1;
        bool flag = nums[0]>0;
        int cnt = 2;
        for(int i=1; i<newn; ++i){
            if((nums[i]>0) ^ flag){
                flag = !flag;
                ++cnt;
            }
        }
        return cnt;
    }
};